package com.googlecode.mailnet.emf.netmodel.visualization.importance;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.Shape;
import org.eclipse.swt.graphics.Color;

import com.googlecode.mailnet.emf.netmodel.simulation.SimulationContext;
import com.googlecode.mailnet.emf.netmodel.visualization.ShapeDecorator;
import com.googlecode.mailnet.info.ILinkInfo;

public class ImportanceLinkDecorator extends ShapeDecorator {
	ILinkInfo linkInfo;
	SimulationContext context;
	
	public ImportanceLinkDecorator(ILinkInfo linkInfo, SimulationContext context) {
		this.linkInfo = linkInfo;
		this.context = context;
	}
	
	public boolean outlineShape(Shape shape, Graphics g) {
		double importance = context.getStatistics().getLinkStats(linkInfo.getLink()).importance;
		long colorBrightness = Math.round(importance * 85.0);
		int width = (int)Math.round(importance * 5.0);
		Color color = new Color(null, 170 + (int)colorBrightness, 170 - (int)colorBrightness * 2, 170 - (int)colorBrightness * 2);
		shape.setForegroundColor(color);
		shape.setLineStyle(linkInfo.isBroken() ? Graphics.LINE_DASH : Graphics.LINE_SOLID);
		shape.setLineWidth(width);
		return false;
	}
}
